/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;

import model.admin.HostelMo;

import vo.CollegeResidentialVo;
import vo.ResidentialRoomVo;
import vo.StudentDetailsVo;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Sony
 * 
 */
public class EditHostelDetails extends ActionSupport {
	int residential_id = 0, room_id1 = 0;
	String type = "";
	String residential_name;
	String residential_type;
	String warden_id;
	String warden_name;
	String capacity;
	String residential_id1;
	String room_number;
	String vacancy;
	String occupancy;
	String room_id;
	String description;
	String occupant_id;
	String roll_number;
	ArrayList<CollegeResidentialVo> hostels = new ArrayList<CollegeResidentialVo>();
	ArrayList<ResidentialRoomVo> rooms = new ArrayList<ResidentialRoomVo>();
	ArrayList<StudentDetailsVo> occupantlist = new ArrayList<StudentDetailsVo>();
	public String execute() {

		if(type.equals("gethosteldetails"))
		{
			HostelMo mo = new HostelMo();
			try {
				hostels = mo.getHostelDetails(residential_id);
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "hostel";
		}
		else if(type.equals("getroomdetails"))
		{
			HostelMo mo = new HostelMo();
			try {
				rooms = mo.getRoomDetails(Integer.parseInt(room_id));
				occupantlist=mo.getOccupantId(Integer.parseInt(room_id));
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "room";
		} else if (type.equals("removestudentfromroom")){
			HostelMo mo = new HostelMo();
		
			try {
				mo.deleteStudentFromRoom(roll_number, Integer.parseInt(room_id),type);
				rooms = mo.getRoomDetails(Integer.parseInt(room_id));
				occupantlist=mo.getOccupantId(Integer.parseInt(room_id));
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		}
		else if(type.equals("addnewroom"))
		{
			//EditHostelDetails hd=new EditHostelDetails();
			setResidential_id(residential_id);
			return "addnewroom";
		}
		else if(type.equals("addnewhostel"))
		{
			return "addnewhostel";
		}
		
		else if (type.equals("edithostel")) {
			HostelMo mo = new HostelMo();
			CollegeResidentialVo vo=new CollegeResidentialVo();
			vo.setResidential_id(residential_id);
			vo.setResidential_name(residential_name);
			vo.setResidential_type(residential_type);
			vo.setWarden_id(Integer.parseInt(warden_id));
			vo.setWarden_name(warden_name);
			vo.setCapacity(Integer.parseInt(capacity));
			try {
				mo.editHostel(vo,"edit",type);
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "hostellist";

		} else if (type.equals("editroom")) {
			HostelMo mo = new HostelMo();
			ResidentialRoomVo vo=new ResidentialRoomVo();
			vo.setRoom_id(Integer.parseInt(room_id));
			vo.setRoom_number(Integer.parseInt(room_number));
			vo.setDescription(description);
			vo.setOccupancy(Integer.parseInt(occupancy));
			vo.setVacancy(Integer.parseInt(vacancy));
			vo.setOccupant_id(occupant_id);
			try {
				//mo.editRoom(vo,"edit");
				mo.updateRoomOccupancy(occupant_id,Integer.parseInt(room_id), Integer.parseInt(room_number), description, Integer.parseInt(vacancy), Integer.parseInt(occupancy),type);
			} catch (Exception e) {
				//e.printStackTrace();
				System.out.println(e.getMessage());
				addActionError(e.getMessage());
			}
			return "roomlist";
		}
		else if (type.equals("addhostel")) {
			HostelMo mo = new HostelMo();
			CollegeResidentialVo vo=new CollegeResidentialVo();
			vo.setResidential_name(residential_name);
			vo.setResidential_type(residential_type);
			vo.setWarden_id(Integer.parseInt(warden_id));
			vo.setWarden_name(warden_name);
			vo.setCapacity(Integer.parseInt(capacity));
			try {
				mo.editHostel(vo,"add",type);
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "hostellist";
		}
		else if (type.equals("addroom")) {
			HostelMo mo = new HostelMo();
			ResidentialRoomVo vo=new ResidentialRoomVo();
			vo.setResidential_id(residential_id);
			vo.setRoom_number(Integer.parseInt(room_number));
			vo.setDescription(description);
			vo.setOccupancy(Integer.parseInt(occupancy));
			vo.setVacancy(Integer.parseInt(vacancy));
			try {
				mo.editRoom(vo,"add",type);
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "roomlist";
		}
		else if(type.equals("deletehostel"))
		{
			HostelMo mo = new HostelMo();
			try {
				mo.deleteHostel(residential_id,type);
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "hostellist";
		}
		else if(type.equals("deleteroom"))
		{
			HostelMo mo = new HostelMo();
			try {
				mo.deleteRoom(Integer.parseInt(room_id),type);
			} catch (Exception e) {
				addActionError(e.getMessage());
			}
			return "roomlist";
		}
		else if(type.equals("assignroom"))
		{
			HostelMo mo = new HostelMo();
			//mo.assignRoom(occupant_id,room_id);
			return "roomlist";
		}
		
		return SUCCESS;
	}

	public String getRoll_number() {
		return roll_number;
	}

	public void setRoll_number(String roll_number) {
		this.roll_number = roll_number;
	}

	public ArrayList<StudentDetailsVo> getOccupantlist() {
		return occupantlist;
	}

	public void setOccupantlist(ArrayList<StudentDetailsVo> occupantlist) {
		this.occupantlist = occupantlist;
	}

	public String getResidential_name() {
		return residential_name;
	}

	public void setResidential_name(String residential_name) {
		this.residential_name = residential_name;
	}

	public String getResidential_type() {
		return residential_type;
	}

	public void setResidential_type(String residential_type) {
		this.residential_type = residential_type;
	}

	public String getWarden_id() {
		return warden_id;
	}

	public void setWarden_id(String warden_id) {
		this.warden_id = warden_id;
	}

	public String getWarden_name() {
		return warden_name;
	}

	public void setWarden_name(String warden_name) {
		this.warden_name = warden_name;
	}

	public String getCapacity() {
		return capacity;
	}

	public void setCapacity(String capacity) {
		this.capacity = capacity;
	}

	public String getResidential_id1() {
		return residential_id1;
	}

	public void setResidential_id1(String residential_id1) {
		this.residential_id1 = residential_id1;
	}

	public String getRoom_number() {
		return room_number;
	}

	public void setRoom_number(String room_number) {
		this.room_number = room_number;
	}

	public String getVacancy() {
		return vacancy;
	}

	public void setVacancy(String vacancy) {
		this.vacancy = vacancy;
	}

	public String getOccupant_id() {
		return occupant_id;
	}

	public void setOccupant_id(String occupant_id) {
		this.occupant_id = occupant_id;
	}

	public String getOccupancy() {
		return occupancy;
	}

	public void setOccupancy(String occupancy) {
		this.occupancy = occupancy;
	}

	public int getRoom_id1() {
		return room_id1;
	}

	public void setRoom_id1(int room_id1) {
		this.room_id1 = room_id1;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public ArrayList<CollegeResidentialVo> getHostels() {
		return hostels;
	}

	public void setHostels(ArrayList<CollegeResidentialVo> hostels) {
		this.hostels = hostels;
	}

	public ArrayList<ResidentialRoomVo> getRooms() {
		return rooms;
	}

	public void setRooms(ArrayList<ResidentialRoomVo> rooms) {
		this.rooms = rooms;
	}

	public int getResidential_id() {
		return residential_id;
	}

	public void setResidential_id(int residential_id) {
		this.residential_id = residential_id;
	}

	public String getRoom_id() {
		return room_id;
	}

	public void setRoom_id(String room_id) {
		this.room_id = room_id;
	}
}
